<?php
/**
* @author : Saeef Ahmad
*/
class Api_Util_Mail_HtmlMailer extends Zend_Mail
{

    //static $fromName = "Smshub System Mail";

    //static $fromEmail = "no-reply@smshub.bd";
    
    /**
     *
     * @var Zend_View
     */
    static $_defaultView;

    /**
     * current instance of our Zend_View
     * @var Zend_View
     */
    protected $_view;

    public function __construct($charset = 'iso-8859-1')
    {
        parent::__construct($charset);
        //$this->setFrom(self::$fromEmail, self::$fromName);
        $this->_view = self::getDefaultView();
    }
    
    /**
     * Change script path of the Zend_View and return the view object
     * 
     * @static
     * @return Zend_View
     */
    protected static function getDefaultView()
    {
        if(self::$_defaultView === null)
        {
            self::$_defaultView = new Zend_View();
            self::$_defaultView->setScriptPath(APPLICATION_PATH .
                    '/templates/scripts/mail');
        }
        return self::$_defaultView;
    }

    /**
     * Send Html Mail
     * 
     * @param string $template Template file path
     * @param string $encoding 
     */
    public function sendHtmlTemplate($template, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE)
    {
        $html = $this->_view->render($template);
        $this->setBodyHtml($html, $this->getCharset(), $encoding);
        $this->send();
    }

    /**
     * Set view params which can be used at html template
     * 
     * @param string $property
     * @param mixed $value
     * @return \Api_Util_HtmlMailer 
     */
    public function setViewParam($property, $value)
    {
        $this->_view->__set($property, $value);
        return $this;
    }

}